% depthsurvey.m
% grabs and maps 1-sec ship depth data
% saves z,y,z data in depth*.mat file

for ii=1:1000 
clf;clear all
npts=30;

load q:\cruise\depthB3.dat
%z=depthA1;z(1:1075,:)=[];a1
%z=depthA1;z(1:300,:)=[];%s8
%z=sio8;z(1:300,:)=[];%s8
z=depthB3;

x=z(:,1);y=z(:,2);z=z(:,3);
n=find(x>-70.95);x(n)=[];y(n)=[];z(n)=[];
%n=find(x<-69.95);x(n)=[];y(n)=[];z(n)=[];
%n=find(y<-67.92);x(n)=[];y(n)=[];z(n)=[];

l=length(z(:,1));cc=clock;
[ cc(5) cc(6);l z(l)]
% save depthA1raw  x y z


%edit raw data
n=find(z<10);z(n)=nan;
x(n)=[];y(n)=[];z(n)=[];
n=find(z>1500);z(n)=nan;
x(n)=[];y(n)=[];z(n)=[];
x=boxave(x,1,10);y=boxave(y,1,10);z=boxave(z,1,10);


% delete outside points for A1
% Lon1=-69.0353;Lat1=-67.0309;
% Lon2=-68.9918;Lat2=-66.9931;
% ppp=find(x>Lon1 & x<Lon2 & y>Lat1 & y<Lat2);
% x=x(ppp);y=y(ppp);z=z(ppp);

% interpolate it to a regular grid
xi=linspace(min(x),max(x),npts);
yi=linspace(min(y),max(y),npts);
[Xi,Yi]=meshgrid(xi,yi); % create meshgrid
Zi=griddata(x,y,z,Xi,Yi); % grid the scattered data at Xi and Yi points
[cs,hh]=contour(Xi,Yi,Zi,'l','k');hold on;
%clabel(cs,hh,'fontsize',10,'color','k','rotation',0)
hold on;

% enter station location
% stnloc=[-69 -67;-69.0198 -67.0187]; A1
%stnloc=[-69-33/60  -66-38/60    ]; % sio8
%stnloc=[-70.5 -68.1; -70.5290  -68.1014]; %B2 807m
stnloc=[-70.9951  -68.2561]; % B3
%plot station location
h=plot(stnloc(1),stnloc(2),'.b');set(h,'markersize',24);
set(gca,'fontw','bold')


% plot ships track
h=plot(x,y,'r.');set(h,'markersize',.5)
%grid
aspect5(-68);
figure(gcf)
mapax(2,0,.5,1);

%Color contour
figure(2);clf;
pcolor(xi,yi,Zi);shading interp;hold on
colormap(flipud(jet));colorbar;
[cs,hh]=contour(Xi,Yi,Zi,'col','w');hold on;
%clabel(cs,hh,'fontsize',10,'color','w','rotation',0)
set(gca,'fontw','bold')
h=plot(x,y,'r.');set(h,'markersize',10,'linew',3);hold on;
h=plot(stnloc(1),stnloc(2),'.b');set(h,'markersize',24);hold on;

% axis([-69.9191  -69.8907  -67.9563  -67.9430])
mapax(1,0,.25,2);
aspect5(-65);
title('B3 Bathymetry M')
figure(gcf)

figure(3)
clf
plot(z)
set(gca,'ydir','reverse')
figure(gcf)

figure(1)
clear all

pause(30)
end